<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>Cesium地球初始化</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }

        .box {
            display: grid;
            align-items: center;
            grid-template-columns: 100px 1fr;
            grid-row-gap: 5px;
            margin-bottom: 10px;
            grid-template-rows: 32px;
        }

        .box>div {
            display: grid;
            grid-template-columns: 0.5fr 0.5fr;
        }

        .box>div>input {
            width: 88px !important;
        }


        .box1 {
            display: grid;
            align-items: center;
            grid-template-columns: 1fr;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <div class="box">
            <label for="screen">屏幕渲染</label>
            <input type="checkbox" checked id="screen" onchange="setScreen()">

            <label for="size">尺寸自适应</label>
            <input type="checkbox" checked id="size" onchange="setsize()">

            <label for="text">标签内容</label>
            <input type="text" id="text" value="要显示的内容" onchange="setText()">

            <label for="fontSize">字体大小</label>
            <input type="number" id="fontSize" value="14" onchange="setFontSize()">


            <label for="offsetX">偏移比例</label>
            <div>
                <input type="number" value="0.5" id="offsetX" onchange="setOffset()">
                <input type="number" value="1" id="offsetY" onchange="setOffset()">
            </div>

            <label for="">文字对齐方式</label>
            <select name="align" id="align" onchange="setAlign()">
                <option value="center">中间对齐</option>
                <option value="left" selected>左对齐</option>
                <option value="right">右对齐</option>
            </select>


            <label for="">渲染模式</label>
            <select name="mode" id="mode1" onchange="setMode()">
                <option value="0" selected>单面不透明</option>
                <option value="1">双面不透明</option>
                <option value="2">单面遮罩</option>
                <option value="3">双面遮罩</option>
                <option value="4">单面透明</option>
                <option value="5">双面透明</option>
                <option value="6">单面未遮挡透明</option>
                <option value="7">双面未遮挡透明</option>
            </select>
            <label for="">漫游旋转类型</label>
            <select name="type" id="type1" onchange="setType()">
                <option value="0">固定模式</option>
                <option value="1" selected>面向屏幕旋转</option>
                <option value="2">绕自身Z轴旋转</option>
            </select>
        </div>

        <div class="box1">
            <button onclick="rePickPosition()" class="btn">重新拾取位置</button>
            <button onclick="startEditing()" class="btn">开启编辑</button>
            <button onclick="flyTo()" class="btn">飞行定位</button>
        </div>
    </div>
    <script>
        /** ---------------------------------地球创建------------------------------------**/
        // Vue中引入方式：import { ESObjectsManager } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';

        const { ESObjectsManager } = XE2['esobjs-xe2-plugin-main']
        const objm = new ESObjectsManager();
        window.g_objm = objm;
        // 创建Cesium视口
        const viewer = objm.createCesiumViewer({
            domid: document.getElementById("app"),
        });
        viewer.ionAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyZmQzMDI1OC1kMWYyLTQ1ZjEtYTJmNS0yMjY1ZDcxZjEyOTkiLCJpZCI6NjQ3MTgsImlhdCI6MTYyOTQzNDM5M30.m8vkzG05QiAfe6JQ0XPK8z_6KuUVMf_CoSY-YlMnAIg"
        // 监听视口状态
        viewer.statusChanged.don(status => {
            if (status == 'Created') {
                // 视口创建完成，飞到初始视角位置
                objm.activeViewer.flyIn([
                    108.85607996971562,
                    33.82085516821778,
                    192696.3211939296
                ], [
                    345.49848698838616,
                    -69.83431262552784,
                    359.9505685536115
                ], 3)
            }
        })
        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "maximumLevel": 18,
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
        });

        /** ---------------------------------文字标记------------------------------------**/

        const { ESTextLabel } = XE2['esobjs-xe2-plugin-main']
        const sceneObject = objm.createSceneObject(ESTextLabel)

        sceneObject.position = [108.95958901729841, 34.21997365328595, 0]
        sceneObject.text = '要显示的内容'
        // 屏幕渲染
        function setScreen() {
            sceneObject.screenRender = !sceneObject.screenRender
            // 非屏幕渲染，则飞行定位下
            if (!sceneObject.screenRender) {
                let timer = setTimeout(() => {
                    sceneObject.flyTo()
                    clearTimeout(timer)
                }, 1000)
            }
        }

        // 尺寸自适应
        function setsize() {
            sceneObject.sizeByContent = !sceneObject.sizeByContent

        }

        // 尺寸
        function setsizeAll() {

            sceneObject.width = Number(document.getElementById('sizeWidth').value)
        }

        // 偏移量
        function setOffset() {
            const offsetX = document.getElementById('offsetX').value
            const offsetY = document.getElementById('offsetY').value
            sceneObject.anchor = [offsetX, offsetY]
        }

        // 渲染模式
        function setMode() {
            sceneObject.renderMode = Number(document.getElementById('mode1').value)

        }

        // 漫游旋转类型
        function setType() {
            sceneObject.rotationType = Number(document.getElementById('type1').value)
        }

        // 重新拾取位置
        function rePickPosition() {
            sceneObject.editing = false
            sceneObject.position = [0, 0, 0]
            startEditing()
        }

        // 开始编辑
        function startEditing() {
            sceneObject.editing = true

        }

        // 飞行定位
        function flyTo() {
            sceneObject.flyTo()
        }

        // 标签内容
        function setText() {
            sceneObject.text = document.getElementById('text').value
        }

        //字体大小
        function setFontSize() {
            sceneObject.fontSize = Number(document.getElementById("fontSize").value)
        }

        // 文字对齐方式
        function setAlign() {
            sceneObject.textAlign = document.getElementById("align").value
        }
    </script>

    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
        <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
</body>

</html>